/********************************************************************
Name: Figure A2: The Distribution of Compliance Rates by Request Decile
Author: Dan Thompson
Date: August 2019
Notes:
********************************************************************/

* Set the working directory 
gl root = "$sanctuary_root"
gl root = "YOUR_WORKING_DIRECTORY"

* Bring in the panel of TRAC outcomes
use "$root/data/panel of outcomes.dta", clear

* Get the share of requests ending in detainer by sheriffs in each county 
collapse (sum) all_sheriff detained_sheriff, by(state county)
gen per_detained_sheriff = detained_sheriff/all_sheriff

* Create a variable storing deciles of the compliance rate
xtile hold_request_decile = all_sheriff, nq(10)

* Run the plot
twoway (kdensity per_detained_sheriff if hold_request_decile==4, lc(gs10)) ///
	(kdensity per_detained_sheriff if hold_request_decile==5, lc(gs9)) ///
	(kdensity per_detained_sheriff if hold_request_decile==6, lc(gs8)) ///
	(kdensity per_detained_sheriff if hold_request_decile==7, lc(gs7)) ///
	(kdensity per_detained_sheriff if hold_request_decile==8, lc(gs6)) ///
	(kdensity per_detained_sheriff if hold_request_decile==9, lc(gs5)) ///
	(kdensity per_detained_sheriff if hold_request_decile==10, lc(gs4)), ///
	legend(off) yti("Density") ///
	xti("Detainer Compliance Rate by Hold Request Decile") ///
	bgcolor(white) graphregion(color(white)) ///
	name("compliance_rate_dist_req_decile", replace)
